function underline2Hump(s: string) {
    return s.replace(/_(\w)/g, function (_all, letter) {
        return letter.toUpperCase()
    })
}

// 字符串的驼峰格式转下划线格式，eg：helloWorld => hello_world
function hump2Underline(s: string) {
    return s.replace(/([A-Z])/g, '_$1').toLowerCase()
}

// JSON对象的key值转换为驼峰式
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const underlineToHump = (obj: any[] | any) => {
    if (obj instanceof Array) {
        obj.forEach(function (v) {
            underlineToHump(v)
        })
    } else if (obj instanceof Object) {
        Object.keys(obj).forEach(function (key) {
            const newKey = underline2Hump(key)
            if (newKey !== key) {
                obj[newKey] = obj[key]
                delete obj[key]
            }
            underlineToHump(obj[newKey])
        })
    }
}

// JSON对象的key值转换为下划线格式
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const humpToUnderline = (obj: any[] | any) => {
    if (obj instanceof Array) {
        obj.forEach(function (v) {
            humpToUnderline(v)
        })
    } else if (obj instanceof Object) {
        Object.keys(obj).forEach(function (key) {
            const newKey = hump2Underline(key)
            if (newKey !== key) {
                obj[newKey] = obj[key]
                delete obj[key]
            }
            humpToUnderline(obj[newKey])
        })
    }
}

export const stringToNumber = (value:string | null) => {
    if (value) {
        return Number(value)
    }
    return undefined
}


// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void {
    let timerId: string | number | NodeJS.Timeout | undefined
  
    return function(this: ThisParameterType<T>, ...args: Parameters<T>): void {
      clearTimeout(timerId)
      timerId = setTimeout(() => func.apply(this, args), delay)
    }
}

export function routeCombine(base:string,...querys:string[]){
    return '/'+base+'/' + querys.join('/')
}